package com.wondersgroup.core.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.wondersgroup.core.mapper.AccessAppMapper;
import com.wondersgroup.core.model.AccessApp;
import com.wondersgroup.core.resultmap.DTOAccessApp;

@Service
public class AccessAppService {

	@Autowired
	private AccessAppMapper accessAppMapper;
	/**
	 * 分页查询所有app数据
	 * @param pageNum 页码
	 * @param pageSize 行数
	 * @return
	 */
	public List<DTOAccessApp> findAll(int pageNum, int pageSize){
		PageHelper.startPage(pageNum, pageSize);
		List<DTOAccessApp> list=accessAppMapper.findAllApps();
		return list;
	}
	/**
	 * 通过id查询对象
	 * @param id
	 * @return
	 */
	public AccessApp findById(int id){
		return accessAppMapper.selectByPrimaryKey(id);
	}
	/**
	 * 通过名称查询对象
	 * @param name
	 * @return
	 */
	public AccessApp findByName(String name){
		return accessAppMapper.findByName(name);
	}
	/**
	 * 新增对象
	 * @param app
	 * @return
	 */
	public int addApp(AccessApp app){
		app.setDelFlag(1);
		app.setCreateDate(new Date());
		app.setLastModifiedDate(new Date());
		return accessAppMapper.insert(app);
	}
	/**
	 * 将对象做删除标记
	 * @param id
	 * @return
	 */
	public int deleteApp(int id){
		return accessAppMapper.fakeDelete(id);
	}
	/**
	 * 修改对象
	 * @param app
	 * @return
	 */
	public int updateApp(AccessApp app){
		return accessAppMapper.renewById(app);
	}
}
